<!-- 正文开始 -->
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 头部操作栏 -->
      <form class="layui-form">
        <div class="layui-form lay-header">
          <div class="toolbar">
            <div class="layui-form-item lay-query-content">
              <div class="lay-query-box">
                <div class="query-lt">
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">IQC任务编号：</label>
                    <div class="layui-input-inline">
                      <input name="code" class="layui-input" type="text" placeholder="请输入质检任务编号" />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">单据编号：</label>
                    <div class="layui-input-inline">
                      <input name="orderCode" class="layui-input" type="text" placeholder="请输入单据编号" />
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">来源：</label>
                    <div class="layui-input-inline">
                      <select name="sourceType">
                        <option value="">请选择来源</option>
                        <option value="1">按采购订单</option>
                        <option value="2">按供应商发货物流</option>
                      </select>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label w-auto">创建时间：</label>
                    <div class="layui-input-inline">
                        <input name="createTime" id="createTime" class="layui-input date-icon" type="text" placeholder="请选择创建时间" style="width: 200px" readonly />
                    </div>
                    <input name="startCreateTime" id="sCreateTime" type="hidden" />
                    <input name="endCreateTime" id="eCreateTime" type="hidden" />
                </div>
                </div>
                <div class="query-rt">
                  <div class="layui-inline">
                    <button type="button" class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit>查询</button>
                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit type="button">重置</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="lay-btn-rows">
            <div class="lay-btn-box">
              <div class="lay-btn-lt">
                <!-- <button id="purQualityTaskBtnAdd" class="layui-btn icon-btn color-reseda" type="button">添加IQC质检任务</button> -->
              </div>
              <div class="lay-btn-rt"></div>
            </div>
          </div>
        </div>
      </form>
      <!-- 表格 -->
      <table class="layui-table" id="purQualityTaskTable" lay-filter="purQualityTaskTable"></table>
    </div>
  </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="purQualityTaskTableBar">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="details">详情</a>
  <a class="layui-btn  layui-btn-xs" lay-event="test">录入质检结果</a>
  <!-- {{# if( d.status=="inspect"){ }} -->
  <!-- <a class="layui-btn layui-btn-xs" lay-event="determine">认领</a> -->
  <!-- {{# } }} -->
  <!-- {{# if( d.status=="inspect"){ }} -->
  <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="close">作废</a> -->
  <!-- {{# } }} -->
</script>

<!-- js部分 -->
<script>
  layui.use(["layer", "form", "table", "admin", "laydate"], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var laydate = layui.laydate;

    form.render("select");
    laydate.render({
            elem: "#createTime",
            type: "date",
            range: true,
            done: function (value, date, endDate) {
                if (value) {
                    var dateValue = value.split(" - ");
                    $("input[name='startCreateTime']").val(dateValue[0] + " 00:00:00");
                    $("input[name='endCreateTime']").val(dateValue[1] + " 23:59:59");
                } else {
                    $("input[name='startCreateTime']").val("");
                    $("input[name='endCreateTime']").val("");
                }
            },
        });
    // 渲染表格
    var insTb = table.render({
      elem: "#purQualityTaskTable",
      url: config.base + "enterprise/purchase/admin/myPurQualityTask/list",
      page: true,
      cellMinWidth: 100,
      cols: [
        [
          { type: "numbers", title: "序号" },
          { field: "code", title: "IQC任务编号", width: 150 },
          { field: "sourceTypeName", title: "任务来源" },
          { field: "orderCode", title: "单据编号" },
          { field: "qcQualityTypeName", title: "质检分类" },
          { field: "qualityTestingNatureName", title: "质检性质" },
          { field: "submissionQuantity", title: "送检数量" },
          { field: "statusName", title: "状态" },
          { field: "creatorName", title: "取样员" },
          { field: "createTime", title: "创建时间" },
          { field: "statusDesc", title: "检验员" },
          { field: "okRate", title: "检出时间" },
          {
            align: "center",
            toolbar: "#purQualityTaskTableBar",
            title: "操作",
            fixed: "right",
            width: 260
          }
        ]
      ],
      done: function (res, curr, count) {
        //移除按钮
      }
    });
    // 工具条点击事件
    table.on("tool(purQualityTaskTable)", function (obj) {
      let data = obj.data;
      if (obj.event === "details") {
        if (data) {
          //   data.type = _type;
          admin.putTempData("workOrderQuaTaskInfoData", data);
        } else {
          admin.putTempData("workOrderQuaTaskInfoData", null);
        }
        admin.formOpen({
          type: 1,
          area: ["80%", "85%"],
          style: "font-size: 20px;",
          title: "质检任务详情",
          path: "components/purchase/purQuality/purQualityTaskDetailForm.html",
          finish: function () {
            table.reload(insTb, {});
          }
        });
      } else if (obj.event === "print") {
        // doPrint(obj);
        // showPrintPurchaseSignForTemplate(data)
      } else if (obj.event === "test") {
        admin.formOpen({
          area: ["90%", "85%"],
          style: "font-size: 20px;",
          title: "录入质检结果",
          path: "components/purchase/purQuality/myPurQualityTaskForm.html",
          success: function () {
            parentData.data = data;
          }
        });
      }
    });

    //监听排序
    table.on("sort(purQualityTaskTable)", function (obj) {
      table.reload("purQualityTaskTable", {
        initSort: obj,
        where: {
          sort: obj.field,
          order: obj.type
        }
      });
    });

    // 搜索
    form.on("submit(formSubSearchLog)", function (data) {
      insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
    });

    // 重置搜索
    form.on("submit(resets)", function (data) {
      insTb.reload({ where: admin.resetSearch(data.field), page: { curr: 1 } }, "data");
      return false;
    });

    // 添加按钮点击事件
    $("#purQualityTaskBtnAdd").click(function () {
      showQualityInspectionTaskModel();
    });

    // 添加质检任务弹窗 && 质检任务详情弹窗
    function showQualityInspectionTaskModel(data, _type) {
      //如果是详情 或者是 修改
      if (data) {
        data.type = _type;
        admin.putTempData("workOrderQuaTaskInfoData", data);
      } else {
        admin.putTempData("workOrderQuaTaskInfoData", null);
      }
      if (data) {
      } else {
        title = "添加IQC质检任务";
        admin.formOpen({
          type: 1,
          area: ["80%", "85%"],
          style: "font-size: 20px;",
          title: title,
          path: "components/purchase/purQuality/purQualityTaskForm.html",
          finish: function () {
            table.reload(insTb, {});
          }
        });
      }
    }
  });
</script>
